package com.atguigu.lease.web.admin.controller.system;

import com.atguigu.lease.common.result.Result;
import com.atguigu.lease.model.entity.UserInfo;
import com.atguigu.lease.web.admin.dto.UserInfoSearchDto;
import com.atguigu.lease.web.admin.service.UserInfoService;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/admin/user")
@Tag(name = "平台用户管理模块")
public class UserInfoController {
    @Resource
    UserInfoService userInfoService;
    @Operation(summary = "条件查询用户分页列表")
    @GetMapping("page")
    public Result<Page<UserInfo>> page(UserInfoSearchDto searchDto){
        return Result.ok(userInfoService.page(searchDto.getPage(UserInfo.class),
                Wrappers.lambdaQuery(UserInfo.class)
                        //当条件不为空 设置status条件
                        .eq( searchDto.getStatus()!=null ,
                                UserInfo::getStatus , searchDto.getStatus() )
                        .like(!StringUtils.isEmpty(searchDto.getPhone()) ,
                                UserInfo::getPhone , searchDto.getPhone())
            )
        );
    }
}
